<?php
namespace BoxSns\Controller\Home;
//use Think\Controller;

class AskController extends CommonController {

	//问答首页

	public function index() {

		$this->type = I('type', "0", "intval");
		$where = array('is_show' => 1);
		$typeWhere = array(
			'1' => array('is_best' => 0),
			'2' => array('is_best' => 1),
			'3' => array('user_id' => $this->user_info['user_id']),
		);
		if ($addWhere = $typeWhere[$this->type]) {
			$where = array_merge($where, $addWhere);
		}
		$this->where = $where;
		$this->display();
	}

	/****问题详情*/
	public function topic() {

		$this->topic_id = I('topic_id');
		$this->data = BoxModel("sns_topic")->where(array('id' => $this->topic_id))->find();
		//dump($this->data);exit();
		$this->backLink = U('all_question');
		BoxModel("sns_topic")->hit_count($this->topic_id);
		if ($pid = $this->data['pid']) {
			$from_data = BoxModel("edu_subject")->where(array('subjectid' => $pid))->find();
			//	dump( $this->from_data);
			$data = array(
				'title' => $from_data['subject'],
				'url' => U('Subject/question', array('subjectid' => $from_data['subjectid'])),
			);
			$this->backLink = U('Subject/question', array('subjectid' => $pid));
			$widgetWhere = "pid='$pid'";
		}
		if ($pid2 = $this->data['pid2']) {
			// dump(array('sectionid' => $pid2));
			$from_data = BoxModel("edu_sections")->where(array('sectionid' => $pid2))->find();
			$data['title'] = " " . $from_data['section'];
			$widgetWhere = "pid2='$pid2'";
		}
		if ($pid3 = $this->data['pid3']) {
			$from_data = BoxModel("edu_knows")->where(array('knowsid' => $pid3))->find();
			$data['title'] = "  " . $from_data['knows'];
			$widgetWhere = "pid3='$pid3'";
		}

		if ($pid4 = $this->data['pid4']) {
			$this->questionsData = BoxModel("edu_questions")->load($pid4);
			//dump(	$this->questionsData);
			$widgetWhere = "pid4='$pid4'";
		}
		if ($widgetWhere) {
			$widgetWhere .= " and type= '" . $this->data['type'] . "'";
		} else {
			$widgetWhere = " and type= '" . $this->data['type'] . "'";
		}
		$this->widgetWhere = $widgetWhere;
		$this->from_data = $data;
		// dump( $this->data);
		$this->display();
	}

}